package org.bultreebank.operators;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
 * Data Object - implementation of Operator interface for performing 
 * Intersection of sets of matching document IDS. Used for searching.
 * @author Aneliya Ticheva
 *
 */
public class Intersection implements Operator<Set<String>> {

	protected List<Set<String>> operands;
	
	public Intersection(List<Set<String>> args) 
	{
		operands = args;
	}
	public void addArgument(Set<String> argument)
	{
		operands.add(argument);
	}
	public Set<String> evaluateOperator()
	{
		if (operands == null || operands.isEmpty())
			return new HashSet<String>();
		if(operands.size() < 2)
			return operands.get(0);
		Set<String> temp = operands.get(0);
		for (Set<String> arg: operands)
			temp.retainAll(arg);
		return temp;
	}

	public int getArgumentsNum() {
		return operands.size();
	}
	public void setArgumentList(List<Set<String>> args)
	{
		operands = args;		
	}

}
